package com.cat.binaryTree;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/sum-root-to-leaf-numbers/
 * @create 2025/9/8 21:16
 * @since JDK17
 */

public class Solution02 {
    int ans = 0;
    int[] num = new int[11];
    void dfs(TreeNode root, int cur) {
        if (root == null) {
            return;
        }
        num[cur] = root.val;
        if (root.left == null && root.right == null) {
            int t = 0;
            for (int i = 0; i < cur; i++) {
                t = t * 10 + num[i];
            }
            ans += t;
            return;
        }
        dfs(root.left, cur + 1);
        dfs(root.right, cur + 1);
    }
    public int sumNumbers(TreeNode root) {

        return ans;
    }
}
